package org.example.trainTicketSystem.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
import org.example.trainTicketSystem.DTO.SaleRecordDTO;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDateTime;

@NoArgsConstructor
@Data
@TableName("sale_record")
public class SaleRecord {

    @TableId(type = IdType.AUTO)
    private Integer saleId;

    @TableField
    private Integer ticketId;

    @TableField
    private Integer userId;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
    @TableField
    private LocalDateTime saleTime;

    @TableField
    private String saleChannel;

    public SaleRecord(SaleRecordDTO saleRecordDTO) {
        this.ticketId = saleRecordDTO.getTicketId();
        this.userId = saleRecordDTO.getUserId();
        this.saleTime=LocalDateTime.now();
        this.saleChannel=saleRecordDTO.getSaleChannel();
    }
}
